package com.example.gs.lenovoapp;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import dalvik.system.DexFile;
import zj.dao.DBHelper;
import zj.method.ZjMethod;
import zj.pojo.ZjObject;
import zj.pojo.inpojo.InGetAllSense;
import zj.pojo.inpojo.InSetCarMove;
import zj.pojo.outpojo.OutGetAllSense;
import zj.pojo.outpojo.OutSetCarMove;
import zj.utils.ZjFinal;

public class MainActivity extends AppCompatActivity {
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case  ZjFinal.GETALLSENSE:
                    OutSetCarMove outSetCarMove = (OutSetCarMove) msg.obj;
                    if (outSetCarMove.getRESULT().equals("S")){
                        Log.i("tag","UI线程执行成功");
                    }
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ZjFinal.classList.add("zj.pojo.outpojo.OutGetAllSense");
        ZjFinal.classList.add("zj.pojo.inpojo.InGetAllSense");
//        Timer timer = new Timer();
//        TimerTask timerTask = new TimerTask() {
//            @Override
//            public void run() {
//                httpRequest_Dao();
//            }
//        };
//        timer.schedule(timerTask,0,1);

    }

    public void httpRequest_UI_stop(View view){
        InSetCarMove zjObject = new InSetCarMove();
        zjObject.setCarAction("Stop");
        zjObject.setCarId(1);
        ZjMethod.ZjUIMethod(handler,zjObject, OutSetCarMove.class,ZjFinal.GETALLSENSE);
    }

    public void httpRequest_UI_start(View view){
        InSetCarMove zjObject = new InSetCarMove();
        zjObject.setCarAction("Start");
        zjObject.setCarId(1);
        ZjMethod.ZjUIMethod(handler,zjObject, OutSetCarMove.class,ZjFinal.GETALLSENSE);
    }

    public void httpRequest_Dao(View view){
        ZjObject zjObject = new InGetAllSense();
        ZjMethod.ZjDaoMethod(this,zjObject, OutGetAllSense.class);
    }

    public void sqlRequest(View view){
        DBHelper db = new DBHelper(this);
        List<ZjObject> zjObjectList = db.queryAll(OutGetAllSense.class);
        for (ZjObject zjObject : zjObjectList){
            Log.i("tag",zjObject.toJsonString());
        }
    }
}
